package com.zhu.library_management_system.repository;

import com.zhu.library_management_system.pojo.BookBorrowing;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.time.LocalDateTime;

@Repository
public interface BookBorrowingRepository extends PagingAndSortingRepository<BookBorrowing,Integer> {
    @Modifying
    @Query("UPDATE BookBorrowing SET realReturnDate = ?2, borrowStatus = ?3, overdueFine = ?4 WHERE id = ?1")
    void realReturnDate(Integer id, LocalDateTime realReturnDate,String borrowStatus, Integer overdueFine);

    @Query("SELECT b.returnDate FROM BookBorrowing b WHERE b.id = ?1")
    LocalDateTime getReturnDate(Integer id);

    @Query("SELECT SUM(b.bookCount) FROM BookBorrowing b WHERE b.userId = ?1 AND b.borrowStatus = '正在借阅中...' ")
    Integer countUserBorrowing(Integer userId);
}
